<%-- 
  -- Body List para Debt.
  --
  -- @author nicolas.gonzalez
--%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<%@ taglib uri="/WEB-INF/displaytag-el.tld" prefix="display" %>
<%@ taglib uri="/WEB-INF/security.tld" prefix="security" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<%-- Librerias para EXT library --%>
<link rel="stylesheet" type="text/css" href="<html:rewrite page='/protected/script/ext-1.1.1/resources/css/ext-all.css'/>" />
<link rel="stylesheet" type="text/css" href="<html:rewrite page='/protected/script/ext-1.1.1/resources/css/xtheme-default.css'/>" />

<script src="<html:rewrite page='/protected/script/ext-1.1.1/adapter/ext/ext-base.js'/>" type="text/javascript"></script>
<script src="<html:rewrite page='/protected/script/ext-1.1.1/ext-all.js'/>" type="text/javascript"></script>

<script type="text/javascript">
	/* Va a la modificacion de la deuda
	 */
	var editDebt = function(id) {
		$("idShowId").value = id;
		
		var form = $("showDebtFormId");
		form.submit();
	}

	/* Va a ver la deuda
	 */
	var viewDebt = function(id) {
		$("idViewId").value = id;
		
		var form = $("viewDebtFormId");
		form.submit();
	}

    /* Lleva al Action que toma el id de la deuda y prepara la
     * pagina de cobro
     */
    var collectDebt = function(debtId) {
        $("debtIdPrepareId").value = debtId;
        
        var form = $("prepareCollectFormId");
        form.submit();
    } 
</script>

<%-- El ID del form NO debe ser modificado. Se usa desde el menu --%>
<html:form action="/protected/listDebts.do" styleId="debtFormId">
    <%-- Inyectados por Javascript --%>
    <html:hidden name="debtForm" property="id" styleId="debtId" value=""/>
    
    <h2>Deudas</h2>
    
    <bean:define id="debts" name="debtForm" property="debts" />
    <display:table  name="pageScope.debts" sort="list" export="true" pagesize="15" requestURI="/protected/listDebts.do" id="row" class="displayTable">
        
        <display:column title="Editar" class="columnGifLink" media="html">
	        <logic:equal name="row" property="debtStatus" value="NO VIGENTE">
	            <img src="<html:rewrite page='/protected/img/kedit.png'/>" alt="" name="submitButton" onclick="editDebt('<bean:write name="row" property="id" />')" title="Modifica la deuda...">
	        </logic:equal>
            <img src="<html:rewrite page='/protected/img/xmag.png'/>" alt="" name="submitButton" onclick="viewDebt('<bean:write name="row" property="id" />')" title="Ver la deuda...">
			<logic:equal name="row" property="debtStatus.collectable" value="true">
	            <img src="<html:rewrite page='/protected/img/money.gif'/>" alt="" name="submitButton" onclick="collectDebt('<bean:write name="row" property="id" />')" title="Cobra la deuda...">
			</logic:equal>
        </display:column>

        <display:column title="Cliente" property="customer.name" sortable="true" />
        <display:column title="Participante" property="student.fullName" sortable="true" />
        <display:column title="Curso" property="course.name" sortable="true" />
        <display:column title="Desde" media="csv excel pdf" property="validityFrom" sortable="true" format="{0,date,dd/MM/yyyy}"/>
        <display:column title="Venc." property="expiry" sortable="true" format="{0,date,dd/MM/yyyy}"/>
        <display:column title="Saldo" property="balance" sortable="true" />
        <display:column title="Estado" property="debtStatus" sortable="true" decorator="ar.uba.fi.posgrado.common.web.util.PosgradoStatusDecorator" />
    </display:table>    

</html:form>

<%-- Form para obtener informacion de la deuda para poder modificar --%>
<div id="showDebtDivId" class="hideClass">
    <html:form action="/protected/showDebt" styleId="showDebtFormId">
        <html:hidden property="id" value="" styleId="idShowId" />
    </html:form>
</div>

<%-- Form para ver la deuda --%>
<div id="viewDebtDivId" class="hideClass">
    <html:form action="/protected/viewDebt" styleId="viewDebtFormId">
        <html:hidden property="id" value="" styleId="idViewId" />
    </html:form>
</div>

<%-- Form para obtener informacion de la deuda --%>
<div id="showCollectDivId" class="hideClass">
    <html:form action="/protected/prepareCollect" styleId="prepareCollectFormId">
        <html:hidden property="debtId" value="" styleId="debtIdPrepareId" />
    </html:form>
</div>